package cn.anline.www.dao;

import cn.anline.www.bean.UserBean;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;


public class UserDao extends JdbcDaoSupport {
    private String msg;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    // 此方法把USEMBO表对应的字段查询出来依次放入userPO中
    public Collection<UserBean> doquery() {
        String sql = "SELECT * FROM user";
        return getJdbcTemplate().query(sql, new RowMapper() {
            @Override

            public Object mapRow(ResultSet rs, int num) throws SQLException {
               UserBean user = new UserBean();
               user.setId(rs.getInt("id"));
               user.setNickname(rs.getString("nickname"));
               user.setPassword(rs.getString("password"));
               user.setAvatar(rs.getString("avatar"));
               return user;
           }
        });
    }
}
